﻿using System;
using OperationPlugins.Validators;
using System.Runtime.Remoting.Messaging;

namespace OperationPlugins.Applications
{
    [Serializable]
    public sealed class JsonValidationReply : MarshalByRefObject, ILogicalThreadAffinative
    {
        public string status { get; set; }

        public string message { get; set; }

        public static JsonValidationReply Error(string errorMessage)
        {
            if (errorMessage == null)
            {
                throw new ArgumentNullException("errorMessage");
            }

            return new JsonValidationReply { status = "error", message = errorMessage };
        }

        public static JsonValidationReply FromException(Exception e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            return new JsonValidationReply {status = "error", message = e.Message};
        }

        public static JsonValidationReply FromMessageContainer(MessageContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return new JsonValidationReply {status = "succeed"};
        }
    }
}
